package com.utonw.carloan.fragment;

import android.util.SparseArray;

import com.utonw.carloan.fragment.applyloan.LoanStepEightFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepFiveFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepFourFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepNineFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepOneFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepSevenFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepSixFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepThreeFragment;

/**
 * Created by SEELE on 2017/3/21.
 */

public class FragmentFactory {

    private static SparseArray<BaseFragment> sFragmentSparseArray=new SparseArray<>();

    public static BaseFragment createLoanFragment(int pos){
        //先从集合中取，如果没有才创建对象
        BaseFragment fragment =sFragmentSparseArray.get(pos);
        if (fragment==null) {
            switch (pos) {
                case 0:
                    fragment = new LoanStepOneFragment();
                    break;

                case 2:
                    fragment = new LoanStepThreeFragment();
                    break;

                case 3:
                    fragment = new LoanStepFourFragment();
                    break;

                case 4:
                    fragment = new LoanStepFiveFragment();
                    break;

                case 5:
                    fragment = new LoanStepSixFragment();
                    break;


                case 6:
                    fragment = new LoanStepSevenFragment();
                    break;

                case 7:
                    fragment = new LoanStepEightFragment();
                    break;

                case 8:
                    fragment = new LoanStepNineFragment();
                    break;

            }
            sFragmentSparseArray.put(pos,fragment);
        }



        return fragment;
    }

    public static void destroy() {
        sFragmentSparseArray.clear();
    }
}
